'''
@Descripttion: 
@Author: Chen Chenxi
@Date: 2019-12-13 13:11:25
@LastEditTime: 2019-12-14 11:12:03
'''
import os
import pymysql

conn = pymysql.connect(host='39.107.112.113', user='root', password='zhangtianze1997', port=3306,db='recogact', charset='utf8')
count = 1
path1 = 'C:/Users/65152/Desktop/urls'
path2 = 'C:/Users/65152/Desktop/baike_result.txt'
path3 = './classInd2.txt'
path4 = './UCF_list/classInd.txt'
cn_list = []
en_list = []

# l = os.listdir(path)
f = open(path2,'r',encoding='utf-8')
content_d = eval(f.read())
f = open(path3,'r',encoding='utf-8')
line = f.readline()
while line:
    cn_list.append(line)
    line = f.readline()
f = open(path4,'r',encoding='utf-8')
line = f.readline()
while line:
    en_list.append(line)
    line = f.readline()

# print(content_d['板球'])
cursor = conn.cursor()

for item in content_d:
    if count == 36 or count == 93:
        count+= 1
        continue
    c_id = count
    label_name_en = en_list[c_id-1]
    label_name_cn = cn_list[c_id-1]
    baike_field = content_d[item]
    insert_sql = ("insert into recact_contentlist (id, c_id,label_name_en, label_name_cn,is_baike,baike_field) values(%d, %d, '%s', '%s', 1,'%s') " % (count, c_id, label_name_en, item, baike_field))
    try:
        cursor.execute(insert_sql)
        print("submit is good")
        conn.commit()
        count+= 1
    except Exception as e:
        print(item)
        print("error is "+str(e))
    
